
package hasthi.wsrf;

import hasthi.common.HasthiException;
import hasthi.common.XmlBeanUtils;

import javax.xml.namespace.QName;

import org.apache.xmlbeans.XmlCursor;

import wsrf.DeleteResourcePropertiesDocument;
import wsrf.DeleteType;
import wsrf.GetResourcePropertyDocument;
import wsrf.GetResourcePropertyDocumentDocument1;
import wsrf.InsertResourcePropertiesDocument;
import wsrf.InsertType;
import wsrf.UpdateResourcePropertiesDocument;
import wsrf.UpdateType;

public class WsrfClientUtils {
    
    public static GetResourcePropertyDocumentDocument1 buildGetResourcePropertyDocumentRequest(){
        GetResourcePropertyDocumentDocument1 document = GetResourcePropertyDocumentDocument1.Factory.newInstance();
        document.addNewGetResourcePropertyDocument();
        return document;
    }
    
    public static GetResourcePropertyDocument buildGetResourcePropertyRequest(QName name){
        GetResourcePropertyDocument document = GetResourcePropertyDocument.Factory.newInstance();
        document.setGetResourceProperty(name);
        return document;
    }
    
    public static InsertResourcePropertiesDocument buildInsertResourcePropertiesRequest(QName name,Object value) throws HasthiException{
        InsertResourcePropertiesDocument reqDoc = InsertResourcePropertiesDocument.Factory.newInstance();
        InsertType insert = reqDoc.addNewInsertResourceProperties().addNewInsert();
        XmlCursor c = insert.newCursor();
        c.toNextToken();
        XmlBeanUtils.addNameValuePair(c, name, value);
        c.dispose();
        return reqDoc;
    }
    
    public static UpdateResourcePropertiesDocument buildUpdateResourcePropertiesRequest(QName name,Object value) throws HasthiException{
        UpdateResourcePropertiesDocument reqDoc = UpdateResourcePropertiesDocument.Factory.newInstance();
        UpdateType update = reqDoc.addNewUpdateResourceProperties().addNewUpdate();
        XmlCursor c = update.newCursor();
        c.toNextToken();
        XmlBeanUtils.addNameValuePair(c, name, value);
        c.dispose();
        return reqDoc;
    }
    
    public static DeleteResourcePropertiesDocument buildDeleteResourcePropertiesRequest(QName name){
        DeleteResourcePropertiesDocument reqDoc = DeleteResourcePropertiesDocument.Factory.newInstance();
        DeleteType delete = reqDoc.addNewDeleteResourceProperties().addNewDelete();
        delete.setResourceProperty(name);
        return reqDoc;
    }
    
//    public static GetResourcePropertyDocumentDocument1 buildGetResourcePropertyDocumentResponseDocument(){
//        
//    } 
    
    
    
    
    
}

